package com.xiaoxi.exam.dao;

import com.xiaoxi.exam.model.Message;
import com.xiaoxi.exam.model.MessageExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface MessageMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    long countByExample(MessageExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int deleteByExample(MessageExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Update({
        "update s_message.t_message",
        "set deleted_at = now()",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Select({
        "insert into s_message.t_message (user_id, open_id, ",
        "message, title, ",
        "type, ",
        "created_at, updated_at, ",
        "deleted_at)",
        "values (#{userId,jdbcType=BIGINT}, #{openId,jdbcType=VARCHAR}, ",
        "#{message,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, ",
        "#{type,jdbcType=SMALLINT,typeHandler=com.xiaoxi.exam.mybatis.typehandlers.EnumCodeHandler}, ",
        "#{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, ",
        "#{deletedAt,jdbcType=TIMESTAMP})", 
        " returning id"
    })
    @Options(useGeneratedKeys=true,keyProperty="id")
    long insertReturningId(Message record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Insert({
        "insert into s_message.t_message (user_id, open_id, ",
        "message, title, ",
        "type, ",
        "created_at, updated_at, ",
        "deleted_at)",
        "values (#{userId,jdbcType=BIGINT}, #{openId,jdbcType=VARCHAR}, ",
        "#{message,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, ",
        "#{type,jdbcType=SMALLINT,typeHandler=com.xiaoxi.exam.mybatis.typehandlers.EnumCodeHandler}, ",
        "#{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, ",
        "#{deletedAt,jdbcType=TIMESTAMP})"
    })
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insert(Message record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    long insertSelectiveReturningId(Message record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int insertSelective(Message record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    List<Message> selectByExample(MessageExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Select({
        "select",
        "id, user_id, open_id, message, title, type, created_at, updated_at, deleted_at",
        "from s_message.t_message",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("com.xiaoxi.exam.dao.MessageMapper.BaseResultMap")
    Message selectByPrimaryKey(Long id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int updateByExampleSelective(@Param("record") Message record, @Param("example") MessageExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int updateByExample(@Param("record") Message record, @Param("example") MessageExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    int updateByPrimaryKeySelective(Message record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table s_message.t_message
     *
     * @mbg.generated Wed Aug 08 14:00:38 CST 2018
     */
    @Update({
        "update s_message.t_message",
        "set user_id = #{userId,jdbcType=BIGINT},",
          "open_id = #{openId,jdbcType=VARCHAR},",
          "message = #{message,jdbcType=VARCHAR},",
          "title = #{title,jdbcType=VARCHAR},",
          "type = #{type,jdbcType=SMALLINT,typeHandler=com.xiaoxi.exam.mybatis.typehandlers.EnumCodeHandler},",
          "created_at = #{createdAt,jdbcType=TIMESTAMP},",
          "updated_at = #{updatedAt,jdbcType=TIMESTAMP},",
          "deleted_at = #{deletedAt,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Message record);
}